home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / bash / bash_108 / bash-108.zoo / bash-1.08 / flags.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-17  |  6.1 KB  |  223 lines

  1. /* flags.c -- Everything about flags except the `set' command.  That
  2.    is in builtins.c */
  3.  
  4. /* Copyright (C) 1987,1989 Free Software Foundation, Inc.
  5.  
  6. This file is part of GNU Bash, the Bourne Again SHell.
  7.  
  8. Bash is free software; you can redistribute it and/or modify it under
  9. the terms of the GNU General Public License as published by the Free
  10. Software Foundation; either version 1, or (at your option) any later
  11. version.
  12.  
  13. Bash is distributed in the hope that it will be useful, but WITHOUT ANY
  14. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16. for more details.
  17.  
  18. You should have received a copy of the GNU General Public License along
  19. with Bash; see the file COPYING.  If not, write to the Free Software
  20. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  21.  
  22. /* Flags hacking. */
  23.  
  24. #define NULL 0x0
  25. #include "flags.h"
  26. #include "config.h"
  27. #include "general.h"
  28. #include "quit.h"
  29.  
  30. /* **************************************************************** */
  31. /*                                    */
  32. /*            The Standard Sh Flags.                */
  33. /*                                    */
  34. /* **************************************************************** */
  35.  
  36. /* Non-zero means automatically mark variables which are modified or created
  37.    as auto export variables. */
  38. int mark_modified_vars = 0;
  39.  
  40. /* Non-zero means exit immediately if a command exits with a non-zero
  41.    exit status. */
  42. int exit_immediately_on_error = 0;
  43.  
  44. /* Non-zero means disable filename globbing. */
  45. int disallow_filename_globbing = 0;
  46.  
  47. /* Non-zero means to locate and remember function commands as functions are
  48.    defined.  Function commands are normally located when the function is
  49.    executed. */
  50. int locate_commands_in_functions = 0;
  51.  
  52. /* Non-zero means that all keyword arguments are placed into the environment
  53.    for a command, not just those that appear on the line before the command
  54.    name. */
  55. int place_keywords_in_env = 0;
  56.  
  57. /* Non-zero means read commands, but don't execute tham.  This is useful
  58.    for debugging shell scripts that should do something hairy and possibly
  59.    desctructive. */
  60. int read_but_dont_execute = 0;
  61.  
  62. /* Non-zero means end of file is after one command. */
  63. int just_one_command = 0;
  64.  
  65. /* Non-zero means don't overwrite existing files while doing redirections. */
  66. int noclobber = 0;
  67.  
  68. /* Non-zero means trying to get the value of $i where $i is undefined
  69.    causes an error, instead of a null substitution. */
  70. int unbound_vars_is_error = 0;
  71.  
  72. /* Non-zero means type out input lines after you read them. */
  73. int echo_input_at_read = 0;
  74.  
  75. /* Non-zero means type out the command definition after reading, but
  76.    before executing. */
  77. int echo_command_at_execute = 0;
  78.  
  79. /* Non-zero means turn off the job control features. */
  80. int jobs_m_flag = 0;
  81.  
  82. /* Non-zero means this shell is interactive, even if running under a
  83.    pipe. */
  84. int forced_interactive = 0;
  85.  
  86. /* **************************************************************** */
  87. /*                                    */
  88. /*             Non-Standard Flags Follow Here.            */
  89. /*                                    */
  90. /* **************************************************************** */
  91.  
  92.  
  93. /* Non-zero means do lexical scoping in the body of a FOR command. */
  94. int lexical_scoping = 0;
  95.  
  96. /* Non-zero means no such thing as invisible variables. */
  97. int no_invisible_vars = 0;
  98.  
  99. /* Non-zero means don't look up or remember command names in a hash table, */
  100. int hashing_disabled = 0;
  101.  
  102. /* Non-zero means that we are doing history expansion.  The default.
  103.    This means !22 gets the 22nd line of history. */
  104. int history_expansion = 1;
  105.  
  106. /* **************************************************************** */
  107. /*                                    */
  108. /*            The Flags ALIST.                */
  109. /*                                    */
  110. /* **************************************************************** */
  111.  
  112. struct flags_alist shell_flags[] = {
  113.  
  114.   /* Standard sh flags. */
  115.   { "a", &mark_modified_vars },
  116.   { "e", &exit_immediately_on_error },
  117.   { "f", &disallow_filename_globbing },
  118.   { "h", &locate_commands_in_functions }, /* Oh, yeah, good mnemonic. */
  119.   { "i", &forced_interactive },
  120.   { "k", &place_keywords_in_env },
  121.   { "n", &read_but_dont_execute },
  122.   { "t", &just_one_command },
  123.   { "u", &unbound_vars_is_error },
  124.   { "v", &echo_input_at_read },
  125.   { "x", &echo_command_at_execute },
  126.   { "C", &noclobber },
  127.  
  128. #if defined (JOB_CONTROL)
  129.   { "m", &jobs_m_flag },
  130. #endif
  131.  
  132.   /* New flags that control non-standard things. */
  133.   { "l", &lexical_scoping },
  134.   { "I", &no_invisible_vars },
  135.  
  136.   /* I want `h', but locate_commands_in_functions has it.  Great. */
  137.   { "d", &hashing_disabled },
  138.  
  139.   /* Once again, we don't have the right mnemonic. */
  140.   { "H", &history_expansion },
  141.  
  142.   {(char *)NULL, (int *)NULL}
  143. };
  144.  
  145.  
  146. int *
  147. find_flag (name)
  148.      char *name;
  149. {
  150.   int i = 0;
  151.   while (shell_flags[i].name) {
  152.     if (strcmp (shell_flags[i].name, name) == 0)
  153.       return (shell_flags[i].value);
  154.     i++;
  155.   }
  156.   return ((int *)FLAG_ERROR);
  157. }
  158.  
  159. /* Change the state of a flag, and return it's original value, or return
  160.    FLAG_ERROR if there is no flag called NAME.  ON_OR_OFF should be one
  161.    of FLAG_ON or FLAG_OFF. */
  162.  
  163. /* With FLAG being a character. */
  164. change_flag_char (flag, on_or_off)
  165.      int flag;
  166.      int on_or_off;
  167. {
  168.   char name[2];
  169.   name[0] = flag; name[1] = '\0';
  170.   return (change_flag (name, on_or_off));
  171. }
  172.  
  173. /* With FLAG being a string. */
  174. change_flag (flag, on_or_off)
  175.   char *flag;
  176.   int on_or_off;
  177. {
  178.   int *value = find_flag (flag);
  179.   int old_value;
  180.  
  181.   if (value == (int *)FLAG_ERROR) return (FLAG_ERROR);
  182.   else old_value = *value;
  183.  
  184.   if (on_or_off == FLAG_ON)
  185.     *value = 1;
  186.   else
  187.     {
  188.       if (on_or_off == FLAG_OFF)
  189.     *value = 0;
  190.       else
  191.     return (FLAG_ERROR);
  192.     }
  193.  
  194. #ifdef JOB_CONTROL
  195.   /* Special hack for the -m flag. */
  196.   if (value == &jobs_m_flag)
  197.     {
  198.       extern set_job_control ();
  199.       set_job_control (on_or_off == '-');
  200.     }
  201. #endif    /* JOB_CONTROL */
  202.     
  203.   return (old_value);
  204. }
  205.  
  206. /* Return a string which is the names of all the currently
  207.    set shell flags. */
  208. char *
  209. which_set_flags ()
  210. {
  211.   char *temp =
  212.     (char *)xmalloc (1 + sizeof (shell_flags) / (2 * sizeof (char *)));
  213.  
  214.   int index, string_index = 0;
  215.  
  216.   for (index = 0; shell_flags[index].name; index++)
  217.     if (*(shell_flags[index].value))
  218.       temp[string_index++] = *(shell_flags[index].name);
  219.  
  220.   temp[string_index] = '\0';
  221.   return (temp);
  222. }
  223.